---@diagnostic disable: lowercase-global, undefined-global, trailing-space

---@type data_componentaction[]
local data = {
    -- 莱瓦汀 烤
    {
        id = 'ACTION_SURTR_LAEVATAIN_COOK',
        str = STRINGS.MOD_SURTR.ACTIONS.ACTION_SURTR_LAEVATAIN_COOK,
        fn = function (act)
            local chef,item,cooker = act.doer,act.invobject,act.target
            if chef and item and cooker then
                if item.components.cookable then
                    local newitem = item.components.cookable:Cook(cooker, chef)
                    ProfileStatsAdd("cooked_"..item.prefab)
                    
                    local sound_inst =
                    cooker.components.inventoryitem ~= nil and
                    cooker.components.inventoryitem:GetGrandOwner() or
                    cooker

                    if sound_inst.SoundEmitter ~= nil then
                        sound_inst.SoundEmitter:PlaySound("dontstarve/wilson/cook")
                    end

                    S_SURTR:consumeOneItem(item)

                    chef.components.inventory:GiveItem(newitem)
                    return true
                end
            end
            return false
        end,
        state = 'doshortaction',
        actiondata = {
            mount_valid = true,
            priority = 10,
        },
        type = "USEITEM",
        component = 'inventoryitem',
        testfn = function (inst, doer, target, actions, right)
            if doer:HasTag("player") and target.prefab and target.prefab == 'surtr_laevatain' and inst:HasTag("cookable") and target.replica.equippable and target.replica.equippable:IsEquipped() then
                return true
            end
            return false
        end
    },
    -- 莱瓦汀 给予一个黄金斧头解锁砍树功能
    {
        id = 'ACTION_SURTR_LAEVATAIN_ACCEPT_AXE',
        str = STRINGS.MOD_SURTR.ACTIONS.ACTION_SURTR_LAEVATAIN_ACCEPT_AXE,
        fn = function (act)
            local wp = act.target
            local obj = act.invobject
            if wp and obj and wp:IsValid() and obj:IsValid() and wp.components.surtr_laevatain_fn then
                wp.components.surtr_laevatain_fn:AddGoldenAxe()
                S_SURTR:consumeOneItem(obj)
                return true
            end
            return false
        end,
        state = 'give',
        actiondata = {
            priority = 10,
            mount_valid = true,
        },
        type = 'USEITEM',
        component = 'inventoryitem',
        testfn = function (inst, doer, target, actions, right)
            return doer:HasTag('player') and target.prefab and target.prefab == 'surtr_laevatain' and inst.prefab and inst.prefab == 'goldenaxe' and target.replica.surtr_laevatain_fn and not target.replica.surtr_laevatain_fn:IsMax_goldenaxe()
        end
    },
    -- 莱瓦汀 给予一个黄金锄头解锁挖矿功能
    {
        id = 'ACTION_SURTR_LAEVATAIN_ACCEPT_MINE',
        str = STRINGS.MOD_SURTR.ACTIONS.ACTION_SURTR_LAEVATAIN_ACCEPT_PICKAXE,
        fn = function (act)
            local wp = act.target
            local obj = act.invobject
            if wp and obj and wp:IsValid() and obj:IsValid() and wp.components.surtr_laevatain_fn then
                wp.components.surtr_laevatain_fn:AddGoldenPickAxe()
                S_SURTR:consumeOneItem(obj)
                return true
            end
            return false
        end,
        state = 'give',
        actiondata = {
            priority = 10,
            mount_valid = true,
        },
        type = 'USEITEM',
        component = 'inventoryitem',
        testfn = function (inst, doer, target, actions, right)
            return doer:HasTag('player') and target.prefab and target.prefab == 'surtr_laevatain' and inst.prefab and inst.prefab == 'goldenpickaxe' and target.replica.surtr_laevatain_fn and not target.replica.surtr_laevatain_fn:IsMax_goldenpickaxe()
        end
    },
    -- 莱瓦汀  给予一个巨人余烬增加4点位面伤害
    {
        id = 'ACTION_SURTR_LAEVATAIN_ACCEPT_ASH',
        str = STRINGS.MOD_SURTR.ACTIONS.ACTION_SURTR_LAEVATAIN_ACCEPT_ASH,
        fn = function (act)
            local wp = act.target
            local obj = act.invobject
            if wp and obj and wp:IsValid() and obj:IsValid() and wp.components.surtr_laevatain_fn then
                wp.components.surtr_laevatain_fn:AddAsh()
                S_SURTR:consumeOneItem(obj)
                return true
            end
            return false
        end,
        state = 'give',
        actiondata = {
            priority = 10,
            mount_valid = true,
        },
        type = 'USEITEM',
        component = 'inventoryitem',
        testfn = function (inst, doer, target, actions, right)
            return doer:HasTag('player') and target.prefab and target.prefab == 'surtr_laevatain' and inst.prefab and inst.prefab == 'surtr_ash' and target.replica.surtr_laevatain_fn and not target.replica.surtr_laevatain_fn:IsMax_ash()
        end
    },
}
return data